package com.melmar.logcomparator;

import java.io.*;
import java.util.*;

class InputStreamEnumerator implements Enumeration<InputStream> {

	private String file = null;

	private static String header = "<log xmlns:log4j=\"http://jakarta.apache.org/log4j/\">";
	
	private static String footer = "</log>";
	
	private int iterator = 0;
	
	public InputStreamEnumerator(String file) {
		this.file = file;
	}

	public boolean hasMoreElements() {
		return iterator < 3;
	}

	public InputStream nextElement() {
		
		InputStream is = null;
		
		switch(iterator) {
		
			case 0 :
				try {
					is = new ByteArrayInputStream(header.getBytes("UTF-8"));
				} catch (UnsupportedEncodingException e1) {	}
				break;
				
			case 1 :
				try {
					is = new FileInputStream(file);
				} catch (FileNotFoundException e1) { }
				break;
				
			case 2 :
				try {
					is = new ByteArrayInputStream(footer.getBytes("UTF-8"));
				} catch (UnsupportedEncodingException e1) {	}
				break;
		}
		
		iterator++;
		
		return is;
	}
}